package com.huike.business.service.impl;


import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper businessTrackRecordMapper;

    @Override
    public List<TbBusinessTrackRecord> selectBusinessRecrod(long businessId) {
        List<TbBusinessTrackRecord> tbBusinessTrackRecords = businessTrackRecordMapper.selectBusinessRecrod(businessId);
        for (TbBusinessTrackRecord tbBusinessTrackRecord : tbBusinessTrackRecords) {
            String keys = tbBusinessTrackRecord.getKeyItems();
            List<String> selectkeys = businessTrackRecordMapper.selectkeys(new String[]{keys});
            tbBusinessTrackRecord.setKeys(selectkeys);
        }
        return businessTrackRecordMapper.selectBusinessRecrod(businessId);
    }

    @Override
    public boolean insertTbBusinessRecord(BusinessTrackVo businessTrackVo) {
        String username = SecurityUtils.getUsername();
        businessTrackVo.setCreateBy(username);
        int i = businessTrackRecordMapper.insertTbBusinessRecord(businessTrackVo);
        int j = businessTrackRecordMapper.updateBusiness(businessTrackVo);
        return i > 0 && j > 0;
    }
}
